#include <iostream>
#include <string>
#include <vector>
#include "Entities.h"
#include "common.pb.h"

using std::vector;
using std::string;
using player::Entity;
using player::Field;

class Adapter {
public:
    static void grpc2cpp(Command* cmd, const Entity* req)
    {
        std::cout<<"grpc2cpp"<<std::endl;
        for(auto &it : req->fields())
        {
            string name = it.name();
            if (name == "command_type")
                cmd->command_type = it.iv(0);        
            else if (name == "speedup")
                cmd->speedup = it.iv(0);
            else if (name == "step_time")
                cmd->step_time = it.iv(0);
        }
        for(auto &it : req->entities())
        {
            string name = it.name();
            if (name == "task")
            {           
                Task task;
                for(auto &tsk : it.fields())
                {
                    string tname = tsk.name();
                    if (tname == "id")
                        task.id = tsk.iv(0);
                    else if (tname == "target_id")
                        task.target_id = tsk.iv(0);
                    else if (tname == "action_id")
                        task.action_id = tsk.iv(0);
                }
                cmd->tasks.push_back(task);
            }
        }
    }
    static void cpp2grpc(Entities* state, Entity* rsp)
    {
        std::cout<<"cpp2grpc"<<std::endl;
    }
};
